home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / csapi / csapi.api < prev    next >
Text File  |  1993-11-02  |  13KB  |  306 lines

  1. 'Spell Input Buffer Structure
  2. Type SpellInputBufferType
  3.     cch As Integer          'total characters in buffer area
  4.     cMdr As Integer         'count of MDR's specified in lrgMdr
  5.     cUdr As Integer         'count of UDR's specified in lrgUdr - should not reference Exclusion UDR's
  6.     wSpellState As Integer  'state relative to previous spellCheck() call
  7.     lrgch As Long           'pointer to buffer area of text to be spell checked
  8.     lrgMdr As Long          'list of main dictionaries to use when spelling the buffer
  9.     lrgUdr As Long          'list of user dictionaries to use when spelling the buffer - should not reference Exclusion UDR's
  10. End Type
  11.  
  12. 'Spell Return Buffer Structure
  13. Type SpellReturnBufferType
  14.     ichError As Integer     'position in the SIB
  15.     cchError As Integer     'length of error "word" in SIB
  16.     scrs As Integer         'spell check return status
  17.     csz As Integer          'count of sz's put in buffer
  18.     cchMac As Integer       'current total of chars in buffer
  19.     cch As Integer          'total space in lrgch. Set by App.
  20.     lrgsz As Long           'pointer to alternatives, null delimited
  21.     lrgbRating As Long      'pointer to rating value for each suggestion returned
  22.     cbRate As Integer       'number of elements in lrgbRating
  23. End Type
  24.  
  25. 'Main Dictionary Structure
  26. Type MdrType
  27.     Mdr As Integer
  28.     Lid As Integer
  29.     Udr As Long
  30. End Type
  31.  
  32. Type WizSpecCharsType
  33.     bIgnore As String * 1
  34.     bHyphenHard As String * 1
  35.     bHyphenSoft As String * 1
  36.     bHyphenNonBreaking As String * 1
  37.     bEmDash As String * 1
  38.     bEnDash As String * 1
  39.     bEllipsis As String * 1
  40.     rgLineBreak As String * 2
  41.     rgParaBreak As String * 2
  42. End Type
  43.  
  44. Declare Sub SpellVer Lib "msspell.dll" (spellVersion As Integer, SpellEngineType As Integer, spellFunctionality As Integer)
  45. Declare Function SpellVerifyMdr Lib "msspell.dll" (ByVal csMainDictionary As String, ByVal lidExpected As Integer, LanguageIdentifier As Integer) As Long
  46. Declare Function SpellInit Lib "msspell.dll" (csSpellIdentifier As Long, Wsc As WizSpecCharsType) As Integer
  47. Declare Function SpellOpenMdr Lib "msspell.dll" (ByVal csSpellIdentifier As Long, ByVal csMainDictionary As String, ByVal ExclusionDictionary As String, ByVal createUdrFlag As Integer, ByVal Cache As Integer, ByVal lidExpected As Integer, csMainDictionaryReference As MdrType) As Integer
  48. Declare Function SpellOpenUdr Lib "msspell.dll" (ByVal csSpellIdentifier As Long, ByVal csUserDictionary As String, ByVal createUdrFlag As Integer, ByVal udrPropertyType As Integer, ByVal udrReferenceId As Integer, ByVal udrReadOnlyFlag As Integer) As Integer
  49. Declare Function SpellOptions Lib "msspell.dll" (ByVal csSpellIdentifier As Long, ByVal SpellOption As Long) As Integer
  50. Declare Function SpellCheck Lib "msspell.dll" (ByVal csSpellIdentifier As Long, ByVal spellCheckCommand As Integer, spellInputBuffer As SpellInputBufferType, spellReturnBuffer As SpellReturnBufferType) As Integer
  51. Declare Function SpellAddChangeUdr Lib "msspell.dll" (ByVal csSpellIdentifier As Long, ByVal udrReferenceId As Integer, ByVal StringToReplace As String, ByVal StringToReplaceWith As String) As Integer
  52. Declare Function SpellTerminate Lib "msspell.dll" (ByVal csSpellIdentifier As Long, ByVal fForce As Integer) As Integer
  53.  
  54. 'Flag values for wSpellState field in Sib
  55. Global Const fssNoStateInfo = 0
  56. Global Const fssIsContinued = 1
  57. Global Const fssStartsSentence = 2
  58. Global Const fssIsEditedChange = 4
  59.  
  60. 'Ram Cache User Dictionary Reference
  61. Global Const udrChangeOnce = &HFFFC       'UDR reserved reference for Change Once List
  62. Global Const udrChangeAlways = &HFFFD     'UDR reserved reference for Change Always List
  63. Global Const udrIgnoreAlways = &HFFFE     'UDR reserved reference for Ignore Always List
  64.  
  65. 'Spell Language ID's
  66. Global Const lidAmerican = &H409
  67. Global Const lidAustralian = &HC09
  68.  
  69. 'Spell Language Definitions
  70. Global Const ldefAmerican = "American English"
  71. Global Const ldefAustralian = "English Australian"
  72.  
  73. 'Spell ID Engine's
  74. Global Const sidSA = 1      'SoftArt
  75. Global Const sidHM = 2      'Houghton-Mifflin
  76.  
  77. 'Spell ID Engine Definitions
  78. Global Const sdefSA = "SoftArt"
  79. Global Const sdefHM = "Houghton-Mifflin"
  80.  
  81. 'Spell Check Command Definitions
  82. Global Const sccVerifyWord = 1
  83. Global Const sccVerifyBuffer = 2
  84. Global Const sccSuggest = 3
  85. Global Const sccSuggestMore = 4
  86. Global Const sccHyphInfo = 5
  87. Global Const sccWildcard = 6
  88. Global Const sccAnagram = 7
  89.  
  90. 'Spell Check return status identifiers
  91. Global Const scrsNoErrors = 0               'all buffers processed
  92. Global Const scrsUnknownInputWord = 1       'unknown word
  93. Global Const scrsNoMoreSuggestions = 8      'no more suggestions
  94. Global Const scrsNoSentenceStartCap = 10    'start of sentence was not captialized
  95. Global Const scrsRepeatWord = 11            'repeat word found
  96.  
  97. Global csSpellIdentifier As Long
  98. Global csMainDictionaryReference As MdrType
  99. Global csMainDictionary As String
  100. Global csUserDictionary As String
  101. Global csTextBuffer As String
  102. Global csTextBufferOffset As Integer
  103. Global csSuggestionList As String
  104. Global csReturnStatus As Integer
  105.  
  106. Global csUnknownWordLength As Integer
  107. Global csUnknownWordStart As Integer
  108.  
  109. 'Spell Options Bitfield Definitions
  110. Global Const soFindUncappedSentences = &H10
  111. Global Const soFindRepeatWord = &H40
  112.  
  113. 'Common Speller
  114. Global Const csChange = 1
  115. Global Const csCancel = 2
  116. Global Const csDone = 3
  117. Global Const csError = 4
  118.  
  119. 'Common Speller Return Status
  120. Global Const csrsChange = 1
  121.  
  122. Dim spellReturnBuffer As SpellReturnBufferType
  123. Dim spellInputBuffer As SpellInputBufferType
  124.  
  125. Dim hInputBuffer%, lpszInputBuffer&, addrInputBuffer&
  126. Dim hAlternativesBuffer%, lpszAlternativesBuffer&, addrAlternativesBuffer&
  127. Dim hRatingsBuffer%, lpszRatingsBuffer&, addrRatingsBuffer&
  128.  
  129. Sub SpellerChange (newWord$)
  130.  
  131.     oldTextBuffer$ = csTextBuffer
  132.     xresume% = csUnknownWordStart + csUnknownWordLength - (Len(newWord$) = 0)
  133.     csTextBuffer = Left$(csTextBuffer, csUnknownWordStart - 1) & newWord$ & Mid$(csTextBuffer, xresume%)
  134.     If csTextBuffer <> oldTextBuffer$ Then csReturnStatus = csChange
  135.  
  136. End Sub
  137.  
  138. Sub SpellerCheck (spellState%, operation%, unknownWord$)
  139.     
  140.     buffer4098$ = Space$(4098)
  141.     rci% = CreateGlobalBuffer(buffer4098$, hInputBuffer%, lpszInputBuffer&, addrInputBuffer&)
  142.     If rci% Then rci% = CreateGlobalBuffer(buffer4098$, hAlternativesBuffer%, lpszAlternativesBuffer&, addrAlternativesBuffer&)
  143.     If rci% Then rci% = CreateGlobalBuffer(buffer4098$, hRatingsBuffer%, lpszRatingsBuffer&, addrRatingsBuffer&)
  144.     If rci% Then
  145.         'populate spell return buffer
  146.         spellReturnBuffer.ichError = 0
  147.         spellReturnBuffer.cchError = 0
  148.         spellReturnBuffer.cch = 4098
  149.         spellReturnBuffer.lrgsz = lpszAlternativesBuffer&
  150.         spellReturnBuffer.lrgbRating = lpszRatingsBuffer&
  151.         spellReturnBuffer.cbRate = 4098
  152.         'populate spell input buffer
  153.         spellInputBuffer.cMdr = 1
  154.         spellInputBuffer.cUdr = 0
  155.         spellInputBuffer.wSpellState = spellState%
  156.         spellInputBuffer.lrgch = lpszInputBuffer&
  157.         spellInputBuffer.lrgMdr = csMainDictionaryReference.Mdr
  158.         spellInputBuffer.lrgUdr = csMainDictionaryReference.Udr
  159.         Select Case operation%
  160.             Case sccVerifyBuffer
  161.                 csTextBufferOffset = csUnknownWordStart + csUnknownWordLength
  162.                 If Len(unknownWord$) = 0 Then unknownWord$ = Mid$(csTextBuffer, csTextBufferOffset)
  163.                 spellInputBuffer.cch = Len(unknownWord$) + 1
  164.                 Call hmemcpy(lpszInputBuffer&, unknownWord$, Len(unknownWord$))
  165.                 rci% = SpellCheck(csSpellIdentifier, sccVerifyBuffer, spellInputBuffer, spellReturnBuffer)
  166.                 If rci% Then
  167.                     csReturnStatus = csError
  168.                 Else
  169.                     Select Case spellReturnBuffer.scrs
  170.                         Case scrsNoSentenceStartCap
  171.                             csUnknownWordStart = spellReturnBuffer.ichError + csTextBufferOffset
  172.                             csUnknownWordLength = spellReturnBuffer.cchError
  173.